Added filter form request to validate JSON #18232
Merged
+127
−16
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This builds upon #18208 by adding a form request for the index API controllers.
We were seeing a lot of rollbars from hosted customers where the
filterpayload being passed was invalid, being passed as?filter=email:[email protected]versus the valid version,?filter={"email":"[email protected]"}:This was previously resulting in a
TypeError: array_filter(): Argument #1 ($array) must be of type array, null givenerror, since we try tojson_decode()thatfiltervalue. The hard error was fixed #18208, but resulted in us silently ignoring the query instead of returning a validation error, which meant the entire result set would be returned. With this PR, the result of invalid JSON there will be:{ "status": "error", "messages": { "filter": [ "The filter field must be a valid JSON string." ] }, "payload": null }I suspect most people with integrations with that API filter haven't been checking the results of the query at all, since it would have been returning a hard 500, so perhaps it doesn't even matter, but this at least returns a useful error instead of potentially erroneous results where the filter was ignored.
This also adds another test and refines the existing one that was looking for the filter field.
We don't typically use form requests for the index pages, since they're not really submitting a form, but instead only passing query strings to search on, but this seemed like a worthwhile one since it is dealing with the request. We'll see what the other devs think though.